import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// 环境变量
import * as dotenv from 'dotenv';
// 响应包装
import { Response } from "@/common/response/response.interceptors"
// 错误拦截
import { ErroFilter } from "@/common/errorFilter/error.filter"


import { ValidationPipe } from '@/common/validation/validation.pipe';

async function bootstrap() {
  dotenv.config();
  
  const app = await NestFactory.create(AppModule);
  app.enableCors({
    origin: 'http://localhost:4173', // 或者指定具体的域名，例如：'https://example.com'
    methods: 'GET,POST,PUT,DELETE,OPTIONS', // 可以根据需求调整方法
    allowedHeaders: 'Content-Type, Authorization, X-Requested-With', // 根据需要调整请求头
    credentials: true, // 如果需要发送凭证（如 cookies）
  });
  app.useGlobalInterceptors(new Response());
  app.useGlobalFilters(new ErroFilter());
  app.useGlobalPipes(new ValidationPipe()); // 注册全局管道
  await app.listen(process.env.PORT ?? 3000);

}
bootstrap();
